import {Component} from '@angular/core';
import {
    AlertController, IonicPage, LoadingController, NavController, NavParams, Platform,
    ToastController
} from 'ionic-angular';
import {SystemService} from "../service/SystemService";
import {UserManager} from "../../framework/manager/UserManager";
import {GuideItemPage} from "./guide-item/guide-item";
import {BasePage} from "../BasePage";
import {AppVersion} from "@ionic-native/app-version";
import {Log} from "../../framework/utils/Log";

/**
 * Generated class for the GuidePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
    selector: 'page-guide',
    templateUrl: 'guide.html',
})
export class GuidePage extends BasePage {
    private static TAG: string = 'GuidePage';
    guideList: Array<any> = new Array();
    context: string;
    private _unitId: string;
    private _year: string;
    searchName:string='';

    constructor(public navCtrl: NavController, public navParams: NavParams, public sys: SystemService, public platform: Platform,
                public loadingCtrl: LoadingController,
                public toastCtrl: ToastController,
                public alertCtrl: AlertController) {
        super(platform, loadingCtrl, toastCtrl, alertCtrl);
    }

    ionViewDidLoad() {
        Log.w(GuidePage.TAG, 'ionViewDidLoad GuidePage');
        this._unitId = UserManager.getInstance().user.unitId;
        this._year = UserManager.getInstance().user.year;
        this.getNotifyInfo();
    }

    getNotifyInfo() {
        this.showLoading(true, '请稍后');
        let data: any = {
            DanWeiBH: this._unitId,
            NianDu: this._year,
            ShiXiangMC:this.searchName
        };
        this.sys.getPayGuideList(data)
            .subscribe((res: any) => {
                Log.printObj(GuidePage.TAG, 'result==', res);
                if (res.msgCode == '1') {
                    this.guideList = res.list;
                } else {
                    this.showError('数据加载失败');
                }
                this.showLoading(false, '请稍后');

            }, error => {
                this.showError('数据加载失败');
                this.showLoading(false, '请稍后');

            });
    }

    detailsHandler(id) {
        this.navCtrl.push(GuideItemPage, {id: id})
    }
    search(){
        this.getNotifyInfo();
    }

}
